
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;
using Evaluant.Uss.ObjectContext.Descriptors;

    

namespace MyNamespace
{
	
	public enum   Title 
	{ 
		Miss,
		Madam,
		Sir
	}

	public partial interface ICode
	{	
		string  Code { get; set; }
		
	}
	
	public partial interface IPerson
	{
		string Id { get; set; }
		DateTime?  Birthday { get; set; }
		string  FirstName { get; set; }
		int?  Age { get; set; }
		System.Drawing.Image  Picture { get; set; }
		
		IEnumerable<IPerson>  Friends { get; }

		IPerson  Deputy { get; }
		Title  Title { get; set; }
		
	}
	
  
  [Serializable]
  public partial class PersonCollection : IPersistableCollection<Person>
	{
		public PersonCollection() : base()
    {
    }

    public PersonCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Person> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Person :  IPersistable, IPerson, ICode 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Friends != null)
				_PersistenceManager.TrackObject(_Friends);
		
			if(_Deputy != null)
				_PersistenceManager.TrackObject(_Deputy);
		
		}
		
	
    protected DateTime? _Birthday;

    public DateTime? Birthday
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Birthday"))
          _Birthday = (DateTime?)this._Entity["Birthday"];
          
        return _Birthday;
      }

      set
      {
        _Birthday = value;
        if(_Entity != null)
			this._Entity["Birthday"] = value;
      }
    }
    
    protected string _FirstName;

    public string FirstName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("FirstName"))
          _FirstName = (string)this._Entity["FirstName"];
          
        return _FirstName;
      }

      set
      {
        _FirstName = value;
        if(_Entity != null)
			this._Entity["FirstName"] = value;
      }
    }
    
    protected int? _Age;

    public int? Age
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Age"))
          _Age = (int?)this._Entity["Age"];
          
        return _Age;
      }

      set
      {
        _Age = value;
        if(_Entity != null)
			this._Entity["Age"] = value;
      }
    }
    
    protected System.Drawing.Image _Picture;

    public System.Drawing.Image Picture
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Picture"))
          _Picture = (System.Drawing.Image)this._Entity["Picture"];
          
        return _Picture;
      }

      set
      {
        _Picture = value;
        if(_Entity != null)
			this._Entity["Picture"] = value;
      }
    }
    
    protected string _Code;

    public string Code
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Code"))
          _Code = (string)this._Entity["Code"];
          
        return _Code;
      }

      set
      {
        _Code = value;
        if(_Entity != null)
			this._Entity["Code"] = value;
      }
    }
    
    protected PersonCollection _Friends;

    [PersistentProperty("_Friends", false)]
    public PersonCollection Friends
    {
      get
      {
        if(_Friends == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("Friends");
          List<Person> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Person>(entities);

          _Friends = new PersonCollection(_PersistenceManager, this, "Friends", items);
        }
        return _Friends;
      }

      set // Defined for Serializable() compatibility only
      {
        _Friends = value;
      }
    }

		
		[NonSerialized]
		private bool _IsDeputyLoaded = false;

		protected Person _Deputy;

		public Person  Deputy
		{
			get 
			{ 
            if(!_IsDeputyLoaded && _PersistenceManager != null && _Entity != null)
            {
            // Inferred relationships
            Entity entity = _Entity.GetEntity("Deputy");
            IList items = null;
            if(entity == null)
            {
                if(_Entity.InferredReferences.Contains("Deputy"))
                    _Deputy = null;
                else
                    items = _PersistenceManager.LoadReference(_Entity, "Deputy");
            }
            else
            {
                items = _PersistenceManager.LoadWithEntities<Person>(new EntitySet( new Entity[] { entity }));
            }

            if(items != null && items.Count > 0)
              _Deputy = (Person)items[0];

            _IsDeputyLoaded = true;
        }

        return _Deputy;
			}			
			set
			{
				// Removes the reference to an existing entity
				if(Deputy != null && _Entity != null)
				{
					_Entity.DeleteElement("Deputy");
				}
				
				// Creates the reference only if it is a concrete entity
				if(value != null && _Entity != null)
				{
					_Entity.AddValue("Deputy", ((IPersistable)value).Entity);
				}
				
				_Deputy = value;
			}
		}			
			
    protected Title   _Title;

      [PersistentProperty("_Title", true)]
      public Title   Title
    {
      get
      {
		    if(_Entity != null)
		    {
			    if(_Entity.IsNull("Title"))
				    _Title = default(Title);
          else
            _Title = (Title)Enum.Parse(typeof(Title), (string)this._Entity["Title"]);
        }

        return _Title;
      }

      set
      {
        _Title = value;
        if(_Entity != null)
            this._Entity["Title"] = Enum.GetName(typeof(Title), value);
      }
    }
      
		IEnumerable<IPerson> IPerson.Friends
		{	                
			get 
			{ 
				foreach(IPerson item in Friends) 
					yield return item;
			}
		}
	
		IPerson IPerson.Deputy
		{
			get { return Deputy; }
		}
		
		public Person ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Person (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface ICompany
	{
		string Id { get; set; }
		string  logo { get; set; }
		
		IEnumerable<IPerson>  Employees { get; }

	}
	
  
  [Serializable]
  public partial class CompanyCollection : IPersistableCollection<Company>
	{
		public CompanyCollection() : base()
    {
    }

    public CompanyCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Company> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Company :  IPersistable, ICompany, ICode 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Employees != null)
				_PersistenceManager.TrackObject(_Employees);
		
		}
		
	
    protected string _logo;

    public string logo
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("logo"))
          _logo = (string)this._Entity["logo"];
          
        return _logo;
      }

      set
      {
        _logo = value;
        if(_Entity != null)
			this._Entity["logo"] = value;
      }
    }
    
    protected string _Code;

    public string Code
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Code"))
          _Code = (string)this._Entity["Code"];
          
        return _Code;
      }

      set
      {
        _Code = value;
        if(_Entity != null)
			this._Entity["Code"] = value;
      }
    }
    
    protected PersonCollection _Employees;

    [PersistentProperty("_Employees", false)]
    public PersonCollection Employees
    {
      get
      {
        if(_Employees == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("Employees");
          List<Person> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Person>(entities);

          _Employees = new PersonCollection(_PersistenceManager, this, "Employees", items);
        }
        return _Employees;
      }

      set // Defined for Serializable() compatibility only
      {
        _Employees = value;
      }
    }

		IEnumerable<IPerson> ICompany.Employees
		{	                
			get 
			{ 
				foreach(IPerson item in Employees) 
					yield return item;
			}
		}
	
		public Company ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Company (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface ISARL
	{
		string Id { get; set; }
		
	}
	
  
  [Serializable]
  public partial class SARLCollection : IPersistableCollection<SARL>
	{
		public SARLCollection() : base()
    {
    }

    public SARLCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<SARL> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class SARL : Company, IPersistable, ISARL 
	{		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Employees != null)
				_PersistenceManager.TrackObject(_Employees);
		
		}
		
	
		public SARL ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public SARL (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public new class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface ILibrary
	{
		string Id { get; set; }
		string  name { get; set; }
		
		IEnumerable<IBook>  MyBooks { get; }

		IShelf  Shelf { get; }
		
	}
	
  
  [Serializable]
  public partial class LibraryCollection : IPersistableCollection<Library>
	{
		public LibraryCollection() : base()
    {
    }

    public LibraryCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Library> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Library :  IPersistable, ILibrary 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_MyBooks != null)
				_PersistenceManager.TrackObject(_MyBooks);
		
			if(_Shelf != null)
				_PersistenceManager.TrackObject(_Shelf);
		
		}
		
	
    protected string _name;

    public string name
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("name"))
          _name = (string)this._Entity["name"];
          
        return _name;
      }

      set
      {
        _name = value;
        if(_Entity != null)
			this._Entity["name"] = value;
      }
    }
    
    protected BookCollection _MyBooks;

    [PersistentProperty("_MyBooks", true)]
    public BookCollection MyBooks
    {
      get
      {
        if(_MyBooks == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("MyBooks");
          List<Book> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Book>(entities);

          _MyBooks = new BookCollection(_PersistenceManager, this, "MyBooks", items);
        }
        return _MyBooks;
      }

      set // Defined for Serializable() compatibility only
      {
        _MyBooks = value;
      }
    }

		
		[NonSerialized]
		private bool _IsShelfLoaded = false;

		protected Shelf _Shelf;

		public Shelf  Shelf
		{
			get 
			{ 
            if(!_IsShelfLoaded && _PersistenceManager != null && _Entity != null)
            {
            // Inferred relationships
            Entity entity = _Entity.GetEntity("Shelf");
            IList items = null;
            if(entity == null)
            {
                if(_Entity.InferredReferences.Contains("Shelf"))
                    _Shelf = null;
                else
                    items = _PersistenceManager.LoadReference(_Entity, "Shelf");
            }
            else
            {
                items = _PersistenceManager.LoadWithEntities<Shelf>(new EntitySet( new Entity[] { entity }));
            }

            if(items != null && items.Count > 0)
              _Shelf = (Shelf)items[0];

            _IsShelfLoaded = true;
        }

        return _Shelf;
			}			
			set
			{
				// Removes the reference to an existing entity
				if(Shelf != null && _Entity != null)
				{
					_Entity.DeleteElement("Shelf");
				}
				
				// Creates the reference only if it is a concrete entity
				if(value != null && _Entity != null)
				{
					_Entity.AddValue("Shelf", ((IPersistable)value).Entity);
				}
				
				_Shelf = value;
			}
		}			
			
		IEnumerable<IBook> ILibrary.MyBooks
		{	                
			get 
			{ 
				foreach(IBook item in MyBooks) 
					yield return item;
			}
		}
	
		IShelf ILibrary.Shelf
		{
			get { return Shelf; }
		}
		
		public Library ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Library (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IShelf
	{
		string Id { get; set; }
		string  name { get; set; }
		
	}
	
  
  [Serializable]
  public partial class ShelfCollection : IPersistableCollection<Shelf>
	{
		public ShelfCollection() : base()
    {
    }

    public ShelfCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Shelf> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Shelf :  IPersistable, IShelf 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected string _name;

    public string name
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("name"))
          _name = (string)this._Entity["name"];
          
        return _name;
      }

      set
      {
        _name = value;
        if(_Entity != null)
			this._Entity["name"] = value;
      }
    }
    
		public Shelf ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Shelf (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IBook
	{
		string Id { get; set; }
		string  name { get; set; }
		
	}
	
  
  [Serializable]
  public partial class BookCollection : IPersistableCollection<Book>
	{
		public BookCollection() : base()
    {
    }

    public BookCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Book> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Book :  IPersistable, IBook 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected string _name;

    public string name
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("name"))
          _name = (string)this._Entity["name"];
          
        return _name;
      }

      set
      {
        _name = value;
        if(_Entity != null)
			this._Entity["name"] = value;
      }
    }
    
		public Book ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Book (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IBabyLibrary
	{
		string Id { get; set; }
		
	}
	
  
  [Serializable]
  public partial class BabyLibraryCollection : IPersistableCollection<BabyLibrary>
	{
		public BabyLibraryCollection() : base()
    {
    }

    public BabyLibraryCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<BabyLibrary> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class BabyLibrary : Library, IPersistable, IBabyLibrary 
	{		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_MyBooks != null)
				_PersistenceManager.TrackObject(_MyBooks);
		
			if(_Shelf != null)
				_PersistenceManager.TrackObject(_Shelf);
		
		}
		
	
		public BabyLibrary ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public BabyLibrary (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public new class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IDog
	{
		string Id { get; set; }
		
		IEnumerable<IDog>  ChildDog { get; }

	}
	
  
  [Serializable]
  public partial class DogCollection : IPersistableCollection<Dog>
	{
		public DogCollection() : base()
    {
    }

    public DogCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Dog> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Dog :  IPersistable, IDog 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_ChildDog != null)
				_PersistenceManager.TrackObject(_ChildDog);
		
		}
		
	
    protected DogCollection _ChildDog;

    [PersistentProperty("_ChildDog", true)]
    public DogCollection ChildDog
    {
      get
      {
        if(_ChildDog == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("ChildDog");
          List<Dog> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Dog>(entities);

          _ChildDog = new DogCollection(_PersistenceManager, this, "ChildDog", items);
        }
        return _ChildDog;
      }

      set // Defined for Serializable() compatibility only
      {
        _ChildDog = value;
      }
    }

		IEnumerable<IDog> IDog.ChildDog
		{	                
			get 
			{ 
				foreach(IDog item in ChildDog) 
					yield return item;
			}
		}
	
		public Dog ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Dog (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}

}
